//
//  SlideAnimator.m
//  LvXi_newVersion
//
//  Created by 王敏 on 16/8/12.
//  Copyright © 2016年 SJT. All rights reserved.
//

#import "SlideAnimator.h"

@implementation SlideAnimator

-(void)xw_setBackAnimation:(id<UIViewControllerContextTransitioning>)transitionContext{
    UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    UIView *containerView = [transitionContext containerView];
    [containerView insertSubview:toVC.view atIndex:0];
    [UIView animateWithDuration:self.backDuration animations:^{
        fromVC.view.x = -ScreenWidth;
    }completion:^(BOOL finished) {
        [transitionContext completeTransition:YES];
    }];

}

-(void)xw_setToAnimation:(id<UIViewControllerContextTransitioning>)transitionContext{
     UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
     UIView *containerView = [transitionContext containerView];
    
     UIImage * image = [LXMallFrame screenShotWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    containerView.layer.contents = (__bridge id)image.CGImage;
    toVC.view.x = -ScreenWidth ;
     [containerView addSubview:toVC.view];
    [UIView animateWithDuration:self.toDuration animations:^{
        toVC.view.x = 0;
    }completion:^(BOOL finished) {
        [transitionContext completeTransition:YES];
    }];
    
}
@end
